package ui.flowManager.expirimentProperties;

import java.util.ArrayList;

import ui.flowManager.expirimentProperties.ExperimentProperties.Agent_Group;

/**
 * 
 * @author vladimir 
 *	The class contain the details of the game 
 */
public class GameRepresentation
{
	
	private int 							numOfPlayers = 0;
	private int 							numOfStudiedAgents = 0;
	
	private	int								numOfTurns = 0;
	private	int								numOfRepeats = 0;
	private String 							observationType = null;
	private ArrayList<AgentRepresentation> 	agentsList	 = null;
	private ArrayList<AgentRepresentation> 	agentsStudiesList = null;
	

	public int getNumOfPlayers(Agent_Group group) {
		if (group == Agent_Group.CONTROL_AGENT)
			return numOfPlayers;
		else
			return numOfStudiedAgents;
	}
	
	/**
	 * @param 	numPlayer
	 * @return 	AgentRepresentation 
	 */
	public AgentRepresentation getPlayer(int numPlayer, Agent_Group group)
	{
		if (group == Agent_Group.CONTROL_AGENT)
		{
			return agentsList.get(numPlayer - 1);
		}
		//studied players
		else 
		{
			return agentsStudiesList.get(numPlayer - 1);
		}
	}


	public int getNumOfRepeats() {
		return numOfRepeats;
	}

	public void setNumOfRepeats(int numOfRepeats) {
		this.numOfRepeats = numOfRepeats;
	}

	public int getNumOfTurns() {
		return numOfTurns;
	}

	public String getObservationType() {
		return observationType;
	}

	public void setGameData(int numOfTurns, int numberOfRepeats, String observation)
	{
		this.numOfTurns 		= numOfTurns;
		this.numOfRepeats 		= numberOfRepeats;
		this.observationType 	= observation;
	}
	
	
	/**
	 * Create players in the game
	 * in every time there is a set to the number the list is become empty
	 * @param numOfPlayers
	 * @param group
	 */
	public void setPlayers(int numOfPlayers, Agent_Group group) {
		//	regular/control players
		if (group == Agent_Group.CONTROL_AGENT)
		{
			this.numOfPlayers 		= numOfPlayers;	
			//new allocation
			this.agentsList  		= new ArrayList<AgentRepresentation>();		
			for(int i = 0; i < numOfPlayers; ++i)
			{
				agentsList.add(new AgentRepresentation());
			}
		}
		//studied players
		else
		{
			this.numOfStudiedAgents = numOfPlayers;
			//new allocation
			this.agentsStudiesList  		= new ArrayList<AgentRepresentation>();		
			for(int i = 0; i < numOfPlayers; ++i)
			{
				agentsStudiesList.add(new AgentRepresentation());
			}			
		}

	}
	
	
	/**
	 * Adding more players for existing game that already
	 *   have players.
	 * @param numberOfPlayers
	 * @param group
	 */
	public void addPlayers(int numberOfPlayers, Agent_Group group)
	{
		if(group == Agent_Group.CONTROL_AGENT)
		{
			for(int i = 0; i < numberOfPlayers; ++i)
			{
				agentsList.add(new AgentRepresentation());
			}
			//update
			this.numOfPlayers = this.numOfPlayers + numberOfPlayers;
		}
		//case it studied players
		else
		{
			for(int i = 0; i < numberOfPlayers; ++i)
			{
				agentsStudiesList.add(new AgentRepresentation());
			}
			//update
			this.numOfStudiedAgents = this.numOfStudiedAgents + numberOfPlayers;	
		}
	}
	
	/**
	 * Remove player from the experiment properties  
	 * @param playerNumber
	 * @param group
	 */
	public void removePlayer(int playerNumber, Agent_Group group)
	{
		if(group == Agent_Group.CONTROL_AGENT)
		{
			this.agentsList.remove(playerNumber - 1);
			//update number of players
			this.numOfPlayers --;
		}
		// case of studied players
		else
		{
			this.agentsStudiesList.remove(playerNumber - 1);
			//update number of players
			this.numOfStudiedAgents --;
		}
	}
	
	public boolean isInitialized()
	{
		return (observationType != null);
	}
	
	
}
